package com.xxh.mqstudy.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicConfig {
    //声明队列
    @Bean
    Queue myqueue1(){
        return new Queue("testTopicQueue1");
    }
    @Bean
    Queue myqueue2(){
        return new Queue("testTopicQueue2");
    }

    //声明交换机
    @Bean
    TopicExchange mytopicExchange(){
        return new TopicExchange("mytopicExchange");
    }

    //绑定队列和交换机
    @Bean
    Binding binding(){
        return BindingBuilder.bind(myqueue1()).to(mytopicExchange()).with("test.key1");
    }
    /**
     * 这里队列2绑定的路由key是个模糊值，只要是test.开头的就会被路由到队列2
     */
    @Bean
    Binding binding2(){
        return BindingBuilder.bind(myqueue2()).to(mytopicExchange()).with("test.#");
    }
}
